package com.wangsh.splider.web.back.controller;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.wangsh.splider.common.pojo.ApiResponse;
import com.wangsh.splider.common.pojo.ApiResponseEnum;
import com.wangsh.splider.common.util.ConstatFinalUtil;
import com.wangsh.splider.common.util.PageInfoUtil;
import com.wangsh.splider.common.util.QRcodeUtil;
import com.wangsh.splider.controller.BaseController;
import com.wangsh.splider.system.pojo.ASysClient;
import com.wangsh.splider.system.pojo.ASysCountry;
import com.wangsh.splider.system.pojo.ASysFile;
import com.wangsh.splider.system.pojo.ASysFileEnum;
import com.wangsh.splider.system.pojo.ASysIp;
import com.wangsh.splider.system.pojo.ASysMailAccount;
import com.wangsh.splider.system.pojo.ASysPro;
import com.wangsh.splider.system.pojo.ASysProxy;
import com.wangsh.splider.system.pojo.ASysShortUrl;
import com.wangsh.splider.system.pojo.ASysWebSite;
import com.wangsh.splider.system.pojo.ASysWebSiteEnum;
import com.wangsh.splider.system.pojo.ASysWebUrl;
import com.wangsh.splider.system.service.ISystemDbService;
import com.wangsh.splider.system.service.ISystemOperService;

/**
 * 	系统后台操作
 * 	@author wangsh
 */
@Controller
@RequestMapping("/back/system/")
public class SystemBackController extends BaseController
{
	@Resource
	private ISystemDbService systemDbService;
	@Resource
	private ISystemOperService systemOperService;

	/**
	 * 添加系统设置管理提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/reloadSystem", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String reloadSystem()
	{
		/* 数据库操作 */
		ApiResponse<Object> apiResponse = this.systemDbService.reloadSystem();
		ConstatFinalUtil.SYS_LOGGER.info("--重新加载结果:{}--", apiResponse.toJSON());
		return apiResponse.toJSON().toJSONString();
	}
	
	/* ==== 系统设置管理开始 ==== */
	/**
	 * 系统设置管理页面
	 * 
	 * @return
	 */
	@RequestMapping("/sysProList")
	public String sysProList(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProList--");
		/* 接收参数 */
		String proType = request.getParameter("proType");
		String ip = request.getParameter("ip");
		if(proType == null)
		{
			proType = "" ; 
		}
		request.setAttribute("proType", proType);
		
		String operType = request.getParameter("operType");
		if(operType == null)
		{
			operType = "" ; 
		}
		/* ip */
		if(ip == null)
		{
			ip = "" ; 
		}
		request.setAttribute("operType", operType);
		request.setAttribute("ip", ip);
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		condMap.put("operType", operType);
		condMap.put("proType", proType);
		condMap.put("ip",ip);

		/*
		 * 查询数据库 所有的数据以JSON的形式返回
		 */
		ApiResponse<ASysPro> response = this.systemDbService.findCondListSysProService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/sysProList";
	}

	/**
	 * 打开添加系统设置管理
	 * 
	 * @return
	 */
	@RequestMapping("/sysProInsert")
	public String sysProInsert()
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProInsert--");
		return "/back/system/sysProInsert";
	}

	/**
	 * 添加系统设置管理提交操作----
	 * 
	 * @return
	 */
	@RequestMapping(value = "/sysProInsertSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysProInsertSubmit(String pubTimeStr, ASysPro sysPro)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProInsertSubmit--");
		/* 为对象赋值 */

		sysPro.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));// 发布时间
		/* 保存结果 */
		ApiResponse response = this.systemDbService.saveOneSysProService(sysPro);
		ConstatFinalUtil.SYS_LOGGER.info("--系统设置管理添加返回结果:{}--", response.toJSON());
		return response.toJSON().toJSONString();
	}

	/**
	 * 打开更新系统设置管理页面
	 * 
	 * @return
	 */
	@RequestMapping("/sysProUpdate")
	public String sysProUpdate(String id, String operType, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysPro> response = this.systemDbService.findOneSysProService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());

		if ("update".equalsIgnoreCase(operType))
		{
			return "/back/system/sysProUpdate";
		}
		return "/back/system/sysProInfo";
	}

	/**
	 * 添加系统设置管理提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/sysProUpdateSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysProUpdateSubmit(String id, HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--SysProUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysPro> response = this.systemDbService.findOneSysProService(condMap);
		/* 获取java对象 */
		ASysPro sysPro = response.getDataOneJava();

		/* 接收参数 */
		String name = request.getParameter("name");
		String engName = request.getParameter("engName");
		String content = request.getParameter("content");
		String status = request.getParameter("status");
		String operType = request.getParameter("operType");
		String proType = request.getParameter("proType");
		String vals = request.getParameter("vals");
		String pubTimeStr = request.getParameter("pubTimeStr");

		/* 设置属性 */
		sysPro.setName(name);
		sysPro.setEngName(engName);
		sysPro.setContent(content);
		sysPro.setStatus(Byte.valueOf(status));
		sysPro.setProType(Byte.valueOf(proType));
		sysPro.setOperType(Byte.valueOf(operType));
		sysPro.setVals(vals);

		sysPro.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		// 更新时间不用获取
		sysPro.setUpdateTime(new Date());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneSysProService(sysPro);

		ConstatFinalUtil.SYS_LOGGER.info("--系统设置管理添加返回结果:{}--", dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}
	
	/**
	 * 系统文件列表页面
	 * @return
	 */
	@RequestMapping("/sysFileList")
	public String sysFileList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysFileList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		String relaId = request.getParameter("relaId");
		String fileType = request.getParameter("fileType");
		String fileRelaType = request.getParameter("fileRelaType");
		request.setAttribute("relaId", relaId);
		request.setAttribute("fileType", fileType);
		request.setAttribute("fileRelaType", fileRelaType);
		
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		condMap.put("fileType",fileType);
		condMap.put("fileRelaType", fileRelaType);
		condMap.put("relaId", relaId);
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<ASysFile> response = this.systemDbService.findCondListSysFileService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/sysFileList";
	}
	
	/**
	 * 打开系统文件添加页面
	 * @return
	 */
	@RequestMapping("/sysFileInsert")
	public String sysFileInsert(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysFileInsert--");
		return "/back/system/sysFileInsert";
	}
	
	/**
	 * 打开系统文件添加页面
	 * @return
	 */
	@RequestMapping(value = "/sysFileInsertSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysFileInsertSubmit(HttpServletRequest request,Model model, ASysFile sysFile)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysFileInsertSubmit--");
		
		ApiResponse<Object> dbResponse = new ApiResponse<Object>();
		try
		{
			String pubTimeStr = request.getParameter("pubTimeStr");
			sysFile.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
			
			dbResponse = this.systemDbService.saveOneSysFileService(sysFile);
			/* 存储结果 */
			model.addAttribute("response", dbResponse.toJSON());
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("添加一条记录失败了",e);
			dbResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			dbResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(dbResponse.getCode() + "") , infoMap);
		}
		return dbResponse.toJSON().toJSONString();
	}
	
	/**
	 * 打开系统文件更新页面
	 * @return
	 */
	@RequestMapping("/sysFileUpdate")
	public String sysFileUpdate(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysFileUpdate--");
		/* 从session中获取信息 */
		String id = request.getParameter("id");
		/* 准备请求的信息 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		ApiResponse<ASysFile> apiResponse = this.systemDbService.findOneSysFileService(condMap);
		ASysFile sysFile = apiResponse.getDataOneJava() ; 
		model.addAttribute("response", apiResponse.toJSON());
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			/* 根据不同的请求跳转不同的页面 */
			return "/back/system/sysFileUpdate";
		}else if("file".equalsIgnoreCase(operType))
		{
			/* 上传文件 */
			model.addAttribute("name", "系统文件上传");
			model.addAttribute("url", "/back/system/sysFileFileUpdateSubmit.htm?operType=" + operType + "&id=" + id);
			
			if(sysFile.getFileRelaType() == ASysFileEnum.FILERELATYPE_FB_USERS.getStatus())
			{
				model.addAttribute("templatePath","/template/facebook_users_template.xlsx");
				model.addAttribute("name", "faceBook用户上传");
			}else if(sysFile.getFileRelaType() == ASysFileEnum.FILERELATYPE_EMAILS_PHONE.getStatus())
			{
				model.addAttribute("templatePath","/template/task_email.csv");
				model.addAttribute("name", "任务邮箱上传");
			}
			return this.uploadFile;
		}
		return "/back/system/sysFileInfo";
	}
	
	/**
	 * 打开系统文件更新页面
	 * @return
	 */
	@RequestMapping(value = "/sysFileUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysFileUpdateSubmit(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysFileUpdateSubmit--");
		ApiResponse<Object> dbResponse = new ApiResponse<Object>();
		try
		{
			/* 从session中获取信息 */
			String id = request.getParameter("id");
			/* 准备请求的信息 */
			Map<String, Object> condMap = new HashMap<String, Object>();
			condMap.put("id", id);
			ApiResponse<ASysFile> apiResponse = this.systemDbService.findOneSysFileService(condMap);
			ASysFile sysFile = apiResponse.getDataOneJava() ; 
			model.addAttribute("response", apiResponse.toJSON());
			
			/* 接收参数 */
			String relaId = request.getParameter("relaId");
			String content = request.getParameter("content");
			
			String fileType = request.getParameter("fileType");
			String fileRelaType = request.getParameter("fileRelaType");
			String status = request.getParameter("status");
			
			sysFile.setRelaId(Integer.valueOf(relaId));
			sysFile.setContent(content);
			
			sysFile.setFileType(Byte.valueOf(fileType));
			sysFile.setFileRelaType(Byte.valueOf(fileRelaType));
			sysFile.setStatus(Byte.valueOf(status));
			
			String pubTimeStr = request.getParameter("pubTimeStr");
			sysFile.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
			
			/* 根据不同的请求跳转不同的页面 */
			dbResponse = this.systemDbService.updateOneSysFileService(sysFile);
			/* 存储结果 */
			model.addAttribute("response", dbResponse.toJSON());
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("更新一条记录失败了",e);
			dbResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			dbResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(dbResponse.getCode() + "") , infoMap);
		}
		return dbResponse.toJSON().toJSONString();
	}
	
	/**
	 * 打开系统文件更新页面
	 * @return
	 */
	@RequestMapping(value = "/sysFileFileUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysFileFileUpdateSubmit(HttpServletRequest request,Model model,MultipartFile file)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysFileUpdateSubmit--");
		ApiResponse<Object> dbResponse = new ApiResponse<Object>();
		try
		{
			/* 从session中获取信息 */
			String id = request.getParameter("id");
			/* 准备请求的信息 */
			Map<String, Object> condMap = new HashMap<String, Object>();
			condMap.put("id", id);
			ApiResponse<ASysFile> apiResponse = this.systemDbService.findOneSysFileService(condMap);
			ASysFile sysFile = apiResponse.getDataOneJava() ; 
			model.addAttribute("response", apiResponse.toJSON());
			
			Map<String, Object> paramsMap = new HashMap<String,Object>();
			try
			{
				if(file != null)
				{
					ConstatFinalUtil.SYS_LOGGER.info("name:{},oriName:{}" , file.getName() , file.getOriginalFilename());
					paramsMap.put("fileName", file.getOriginalFilename());
					paramsMap.put("inputStream", file.getInputStream());
					paramsMap.put("fileSize", file.getSize());
				}
			} catch (IOException e)
			{
				ConstatFinalUtil.SYS_LOGGER.error("上传文件失败了;");
			}
			
			/* 根据不同的请求跳转不同的页面 */
			dbResponse = this.systemDbService.updateOneSysFileService(sysFile,paramsMap);
			/* 存储结果 */
			model.addAttribute("response", dbResponse.toJSON());
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("更新一条记录失败了",e);
			dbResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			dbResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(dbResponse.getCode() + "") , infoMap);
		}
		return dbResponse.toJSON().toJSONString();
	}
	
	//country模块
	
	
	/**
	 * country列表页面
	 * @return
	 */
	@RequestMapping("/sysCountryList")
	public String countryList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysCountryList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<ASysCountry> response = this.systemDbService.findCondListCountryService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/sysCountryList";
	}

	/**
	 * 打开添加country页面
	 * @return
	 */
	@RequestMapping("/sysCountryInsert")
	public String countryInsert()
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysCountryInsert--");
		return "/back/system/sysCountryInsert";
	}
	
	/**
	 * 添加country提交操作
	 * @return
	 */
	@RequestMapping(value = "/sysCountryInsertSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String countryInsertSubmit(HttpServletRequest request,String pubTimeStr)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysCountryInsertSubmit--");
		ApiResponse<Object> response = new ApiResponse<Object>();
		
		Map<String, Object> condMap =new HashMap<String, Object>();
		String name=request.getParameter("name");
		condMap.put("name", name);
		ApiResponse<ASysCountry> apiResponse = this.systemDbService.findOneCountryService(condMap );
		if(apiResponse.getDataOneJava() == null)
		{
			 ASysCountry sysCountry =new ASysCountry();
			 /* 接收参数 */
			 String name1 = request.getParameter("name");
			 String engName = request.getParameter("engName");
			 String language = request.getParameter("language");
			 String allName = request.getParameter("allName");
			 String acceptLanguage = request.getParameter("acceptLanguage");
			 String status = request.getParameter("status");
			 String pubTimeStr1 = request.getParameter("pubTimeStr");
			 String content = request.getParameter("content");
			 /* 设置属性 */
			 sysCountry.setName(name1);
			 sysCountry.setEngName(engName);
			 sysCountry.setLanguage(language);
			 sysCountry.setAllName(allName);
			 sysCountry.setAcceptLanguage(acceptLanguage);
			 sysCountry.setContent(content);
			 sysCountry.setStatus(Byte.valueOf(status));
			 sysCountry.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr1));
			 sysCountry.setUpdateTime(new Date());
			 response = this.systemDbService.saveOneCountryService(sysCountry);
			 ConstatFinalUtil.SYS_LOGGER.info("--sysCountry添加返回结果:{}--",response.toJSON());
		}else
		{
			response.setInfo("数据已存在", Collections.EMPTY_MAP);
		}
	 
		return response.toJSON().toJSONString();
	}
	
	/**
	 * 打开更新country页面
	 * @return
	 */
	@RequestMapping("/sysCountryUpdate")
	public String countryUpdate(String id , String operType , Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysCountryUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysCountry> response = this.systemDbService.findOneCountryService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());
		
		if("update".equalsIgnoreCase(operType))
		{
			return "/back/system/sysCountryUpdate";
		}
		return "/back/system/sysCountryInfo";
	}
	
	/**
	 * 添加country提交操作
	 * @return
	 */
	@RequestMapping(value = "/sysCountryUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String countryUpdateSubmit(String id,
			HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysCountryUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysCountry> response = this.systemDbService.findOneCountryService(condMap);
		/* 获取java对象 */
		ASysCountry country = response.getDataOneJava() ;
		
		 
		/* 接收参数 */
		String name = request.getParameter("name");
		String engName = request.getParameter("engName");
		String language = request.getParameter("language");
		String allName = request.getParameter("allName");
		String acceptLanguage = request.getParameter("acceptLanguage");
		String status = request.getParameter("status");
		String pubTimeStr = request.getParameter("pubTimeStr");
		String content = request.getParameter("content");
		/* 设置属性 */
		country.setName(name);
		country.setEngName(engName);
		country.setLanguage(language);
		country.setAllName(allName);
		country.setAcceptLanguage(acceptLanguage);
		country.setContent(content);
		country.setStatus(Byte.valueOf(status));
		
		country.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		country.setUpdateTime(new Date());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneCountryService(country);
		ConstatFinalUtil.SYS_LOGGER.info("--sysCountry添加返回结果:{}--",dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}
	
	/**
	 * country批量操作
	 * @return
	 */
	@RequestMapping(value = "/sysCountryBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String countryBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysCountryBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		if(ids != null)
		{
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<ASysCountry> apiResponseDb = this.systemDbService.findOneCountryService(condMap);
					ASysCountry country = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					country.setStatus(Byte.valueOf(status));
					country.setPubTime(new Date());
					
					ApiResponse<Object> countryClassResponse = this.systemDbService.updateOneCountryService(country);
					if(countryClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}
			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
	
 
			
		 
	

	/**
	 * country初始化操作
	 * @return
	 */
	@RequestMapping(value = "/sysCountryInit" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String countryInit(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysCountryInit--");
		ApiResponse<ASysCountry> apiResponse = new ApiResponse<ASysCountry>();
		Map<String, Object> condMap =new HashMap<>();
		Map<String, Object> condMap1 =new HashMap<>();
		condMap1.put("status", "1");
		ApiResponse<ASysCountry> apiResponse2 = systemDbService.findCondListCountryService(null, condMap1);
		List<ASysCountry> dataListJava = apiResponse2.getDataListJava();
		if(dataListJava != null)
		{
			 
			int totalNum = dataListJava.size() ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < dataListJava.size(); i++)
			{
				ASysCountry sysCountry = dataListJava.get(i);
				if(sysCountry.getStatus() == 1)
				{
					condMap.clear();
					condMap.put("id", sysCountry.getId());
					ApiResponse<ASysCountry> apiResponseDb = this.systemDbService.findOneCountryService(condMap);
					ASysCountry country = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					country.setStatus(Byte.valueOf("0"));
					country.setPubTime(new Date());
					
					ApiResponse<Object> countryClassResponse = this.systemDbService.updateOneCountryService(country);
					if(countryClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}
			
				StringBuffer sb = new StringBuffer();
				sb.append("总条数:" + totalNum + ";");
				sb.append("成功条数:" + succedNum + ";");
				sb.append("失败条数:" + failedNum + ";");
				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
				apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
			
		}
				return apiResponse.toJSON().toJSONString();
	}
	 
	/**
	 * ip列表页面
	 * @return
	 */
	@RequestMapping("/sysIpList")
	public String ipList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--ipList--");
		String id =request.getParameter("id");
		request.setAttribute("id",id);
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		condMap.put("id",id);
		ApiResponse<ASysIp> response = this.systemDbService.findCondListSysIpService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/sysIpList";
	}

	/**
	 * 打开添加ip页面
	 * @return
	 */
	@RequestMapping("/sysIpInsert")
	public String ipInsert()
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysIpInsert--");
		return "/back/system/sysIpInsert";
	}
	
	/**
	 * 添加ip提交操作
	 * @return
	 */
	@RequestMapping(value = "/sysIpInsertSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String ipInsertSubmit(String ip , ASysIp sysip , HttpServletRequest request)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--ipInsertSubmit--");								
		/* 返回Ip */
		ApiResponse<ASysIp> apiResponse = this.systemOperService.operFindIp(ip);
		return apiResponse.toJSON().toJSONString();
	}
	
	/**
	 * 打开更新ip页面
	 * @return
	 */
	@RequestMapping("/sysIpUpdate")
	public String ipUpdate(String id , String operType , Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--ipUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysIp> response = this.systemDbService.findOneSysIpService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());
		
		if("update".equalsIgnoreCase(operType))
		{
			return "/back/system/sysIpUpdate";
		}
		return "/back/system/sysIpInfo";
	}
	
	/**
	 * 添加ip提交操作
	 * @return
	 */
	@RequestMapping(value = "/sysIpUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String ipUpdateSubmit(String id,
			HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--ipUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysIp> response = this.systemDbService.findOneSysIpService(condMap);
		/* 获取java对象 */
		ASysIp sysIp = response.getDataOneJava() ;
		
		/* 接收参数 */
		String name = request.getParameter("name");
		String ip = request.getParameter("ip");
		String ipStr = request.getParameter("ipStr");
		String isp = request.getParameter("isp");
		String aresponse = request.getParameter("response");
		String content = request.getParameter("content");
		String status = request.getParameter("status");
		String pubTimeStr = request.getParameter("pubTimeStr");
		/* 设置属性 */
		sysIp.setName(name);
		sysIp.setIp(ip);
		sysIp.setIpStr(ipStr);
		sysIp.setIsp(isp);
		sysIp.setResponse(aresponse);
		sysIp.setContent(content);
		sysIp.setStatus(Byte.valueOf(status));		
		sysIp.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		sysIp.setUpdateTime(new Date());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneSysIpService(sysIp);
		ConstatFinalUtil.SYS_LOGGER.info("--ip添加返回结果:{}--",dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}
	
	/**
	 * ip批量操作
	 * @return
	 */
	@RequestMapping(value = "/sysIpBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String ipBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysIpBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		ConstatFinalUtil.SYS_LOGGER.info("--------{}--",operType);
		if(ids != null)
		{
			//ConstatFinalUtil.SYS_LOGGER.info("status的值不不不不不为null");
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					ConstatFinalUtil.SYS_LOGGER.info("--------{}--",status);
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<ASysIp> apiResponseDb = this.systemDbService.findOneSysIpService(condMap);
					ASysIp sysIp = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					sysIp.setStatus(Byte.valueOf(status));
					sysIp.setPubTime(new Date());
					
					ApiResponse<Object> ipClassResponse = this.systemDbService.updateOneSysIpService(sysIp);
					if(ipClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		//ConstatFinalUtil.SYS_LOGGER.info("status的值为null");
		return apiResponse.toJSON().toJSONString();
	}
	
	/* ========ip-代理列表=====           */
	/**
	 * ip-代理列表页面
	 * @return
	 */
	@RequestMapping("/sysProxyList")
	public String sysProxyList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProxyList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		//获取私有的搜索条件
			String pt = request.getParameter("proxyType");
			String ci = request.getParameter("countryId");
			if (pt !=null && !"".equals(pt)) {
				int proxyType = Integer.valueOf(pt);
				condMap.put("proxyType", proxyType);
				request.setAttribute("proxyType", proxyType);
			}
			if (ci !=null&&!"".equals(ci)) {
				int countryId = Integer.valueOf(ci);
				condMap.put("countryId", countryId);
				request.setAttribute("countryId", countryId);
			}
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<ASysProxy> response = this.systemDbService.findCondListSysProxyService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/sysProxyList";
	}
	
	/**
	 * 打开添加ip-代理页面
	 * @return
	 */
	@RequestMapping("/sysProxyInsert")
	public String sysProxyInsert()
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProxyInsert--");
		return "/back/system/sysProxyInsert";
	}
	
	/**
	 * 添加ip-代理提交操作
	 * @return
	 */
	@RequestMapping(value = "/sysProxyInsertSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysProxyInsertSubmit(String pubTimeStr,ASysProxy sysProxy)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProxyInsertSubmit--");
		HashMap<String,Object> condMap = new HashMap<String,Object>();
		HashMap<String,Object> condMap2 = new HashMap<String,Object>();
		ApiResponse<Object> response = new ApiResponse<Object>();
		condMap.put("ip", sysProxy.getIp());
		//根据前端传的ip去查  ip表中查找是否存在 不存在就保存 他自动保存 不用你管 肯定返回返回id
		ApiResponse<ASysIp> ipResponse = systemOperService.operFindIp(sysProxy.getIp());
		condMap2.put("ip", sysProxy.getIp());
		condMap2.put("port", sysProxy.getPort());
		//根据前段传的ip去proxy表中查有的话代表之前保存过了
		ApiResponse<ASysProxy> proxyResponse = systemDbService.findOneSysProxyService(condMap2);
		if (proxyResponse.getDataOneJava() == null) {
			ASysIp sysIp = ipResponse.getDataOneJava();
			//设置国家id
			sysProxy.setCountryId(sysIp.getCountryId());
			//设置ipid
			sysProxy.setIpId(sysIp.getId());
			/* 为对象赋值 */
			sysProxy.setRandInt(UUID.randomUUID().variant());
			sysProxy.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
			sysProxy.setCreateTime(new Date());
			sysProxy.setUpdateTime(new Date());
			/* 保存结果 */
			response = this.systemDbService.saveOneSysProxyService(sysProxy);
			ConstatFinalUtil.SYS_LOGGER.info("--ip-代理添加返回结果:{}--",response.toJSON());
		}else {
			response.setInfo("数据已存在", Collections.EMPTY_MAP);
		}
		
		return response.toJSON().toJSONString();
	}
	
	/**
	 * 打开更新ip-代理页面
	 * @return
	 */
	@RequestMapping("/sysProxyUpdate")
	public String sysProxyUpdate(String id , String operType , Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProxyUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysProxy> response = this.systemDbService.findOneSysProxyService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());
		
		if("update".equalsIgnoreCase(operType))
		{
			return "/back/system/sysProxyUpdate";
		}
		return "/back/system/sysProxyInfo";
	}
	
	/**
	 * 添加ip-代理提交操作
	 * @return
	 */
	@RequestMapping(value = "/sysProxyUpdateSubmit",produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysProxyUpdateSubmit(String id,
			HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProxyUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysProxy> response = this.systemDbService.findOneSysProxyService(condMap);
		/* 获取java对象 */
		ASysProxy sysProxy = response.getDataOneJava() ;
		
		/* 接收参数 */
		String countryId =  request.getParameter("countryId");
		String port =  request.getParameter("port");
		String ipId =  request.getParameter("ipId");
		String ip =  request.getParameter("ip");
		String content = request.getParameter("content");
		String status = request.getParameter("status");
		String pubTimeStr = request.getParameter("pubTimeStr");
		/* 设置属性 */
		sysProxy.setCountryId(Integer.valueOf(countryId));
		sysProxy.setIpId(Integer.valueOf(ipId));
		sysProxy.setIp(ip);
		sysProxy.setPort(port);
		sysProxy.setContent(content);
		sysProxy.setStatus(Byte.valueOf(status));
		sysProxy.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		sysProxy.setUpdateTime(new Date());
		sysProxy.setRandInt(UUID.randomUUID().variant());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneSysProxyService(sysProxy);
		ConstatFinalUtil.SYS_LOGGER.info("--ip-代理添加返回结果:{}--",dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}
	
	/**
	 * ip-代理批量操作
	 * @return
	 */
	@RequestMapping(value = "/sysProxyBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String sysProxyBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysProxyBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		if(ids != null)
		{
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<ASysProxy> apiResponseDb = this.systemDbService.findOneSysProxyService(condMap);
					ASysProxy sysProxy = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					sysProxy.setStatus(Byte.valueOf(status));
					sysProxy.setPubTime(new Date());
					
					ApiResponse<Object> sysProxyClassResponse = this.systemDbService.updateOneSysProxyService(sysProxy);
					if(sysProxyClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}
			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
	
	
	//邮箱账号模块
	
	
		/**
		 * 邮箱账号列表页面
		 * @return
		 */
		@RequestMapping("/sysMailAccountList")
		public String mailAccountList(HttpServletRequest request,Model model)
		{
			ConstatFinalUtil.SYS_LOGGER.info("--sysMailAccountList--");
			/* 分页信息 */
			PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
			/* 搜索条件,生成公共的搜索条件 */
			Map<String, Object> condMap = this.proccedSearch(request);
			/* 查询数据库
			 * 所有的数据以JSON的形式返回
			 *  */
			ApiResponse<ASysMailAccount> response = this.systemDbService.findCondListMailAccountService(pageInfoUtil, condMap);
			/* 将结果存储到Request中 */
			model.addAttribute("response", response.toJSON());
			return "/back/system/sysMailAccountList";
		}

		/**
		 * 打开添加邮箱账号页面
		 * @return
		 */
		@RequestMapping("/sysMailAccountInsert")
		public String mailAccountInsert()
		{
			ConstatFinalUtil.SYS_LOGGER.info("--sysMailAccountInsert--");
			return "/back/system/sysMailAccountInsert";
		}
		
		/**
		 * 添加邮箱账号提交操作
		 * @return
		 */
		@RequestMapping(value = "/sysMailAccountInsertSubmit",produces = "text/html;charset=UTF-8")
		@ResponseBody
		public String mailAccountInsertSubmit(HttpServletRequest request,String pubTimeStr)
		{
			ConstatFinalUtil.SYS_LOGGER.info("--sysMailAccountInsertSubmit--");
			ApiResponse<Object> response = new ApiResponse<Object>();
			
			Map<String, Object> condMap =new HashMap<String, Object>();
			String name=request.getParameter("userName");
			condMap.put("userName", name);
			ApiResponse<ASysMailAccount> apiResponse = this.systemDbService.findOneMailAccountService(condMap );
			ASysMailAccount dataOneJava = apiResponse.getDataOneJava();
			if(dataOneJava == null)
			{
				 ASysMailAccount sysMailAccount = new ASysMailAccount();
				 /* 接收参数 */
				 String username = request.getParameter("userName");
				 String pass = request.getParameter("password");
				 String host = request.getParameter("host");
				 String status = request.getParameter("status");
				 String pubTimeStr1 = request.getParameter("pubTimeStr");
				 String content = request.getParameter("content");
				 /* 设置属性 */
				 sysMailAccount.setUserName(username);
				 sysMailAccount.setPassword(pass);
				 sysMailAccount.setHost(host);
				 sysMailAccount.setContent(content);
				 sysMailAccount.setStatus(Byte.valueOf(status));
				 sysMailAccount.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr1));
				 sysMailAccount.setCreateTime(new Date());
				 sysMailAccount.setUpdateTime(new Date());
				 sysMailAccount.setSendTime(new Date());
				 response = this.systemDbService.saveOneMailAccountService(sysMailAccount);
				 ConstatFinalUtil.SYS_LOGGER.info("--sysCountry添加返回结果:{}--",response.toJSON());
			}else
			{
				response.setInfo("数据已存在", Collections.EMPTY_MAP);
			}
		 
			return response.toJSON().toJSONString();
		}
		
		/**
		 * 打开更新邮箱账号页面
		 * @return
		 */
		@RequestMapping("/sysMailAccountUpdate")
		public String mailAccountUpdate(String id , String operType , Model model)
		{
			ConstatFinalUtil.SYS_LOGGER.info("--sysMailAccountUpdate--");
			/* 准备查询条件 */
			Map<String, Object> condMap = new HashMap<String, Object>();
			condMap.put("id", id);
			/* 查询数据库 */
			ApiResponse<ASysMailAccount> response = this.systemDbService.findOneMailAccountService(condMap);
			/* 存储request */
			model.addAttribute("response", response.toJSON());
			
			if("update".equalsIgnoreCase(operType))
			{
				return "/back/system/sysMailAccountUpdate";
			}
			return "/back/system/sysMailAccountInfo";
		}
		
		/**
		 * 添加邮箱账号提交操作
		 * @return
		 */
		@RequestMapping(value = "/sysMailAccountUpdateSubmit",produces = "text/html;charset=UTF-8")
		@ResponseBody
		public String mailAccountUpdateSubmit(String id,
				HttpServletRequest request,Model model)
		{
			ConstatFinalUtil.SYS_LOGGER.info("--sysMailAccountUpdateSubmit--");
			/* 准备查询条件 */
			Map<String, Object> condMap = new HashMap<String, Object>();
			condMap.put("id", id);
			/* 查询数据库 */
			ApiResponse<ASysMailAccount> response = this.systemDbService.findOneMailAccountService(condMap);
			/* 获取java对象 */
			ASysMailAccount account = response.getDataOneJava() ;
			
			 
			/* 接收参数 */
			 String userName = request.getParameter("userName");
			 String pass = request.getParameter("password");
			 String host = request.getParameter("host");
			String status = request.getParameter("status");
			String pubTimeStr = request.getParameter("pubTimeStr");
			String content = request.getParameter("content");
			/* 设置属性 */
			account.setUserName(userName);
			account.setPassword(pass);
		    account.setHost(host);
			account.setContent(content);
			account.setStatus(Byte.valueOf(status));
			
			account.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
			account.setUpdateTime(new Date());
			/* 数据库操作 */
			ApiResponse dbRes = systemDbService.updateOneMailAccountService(account);
			ConstatFinalUtil.SYS_LOGGER.info("--sysCountry添加返回结果:{}--",dbRes.toJSON());
			return dbRes.toJSON().toJSONString();
		}
		
		/**
		 * 邮箱账号批量操作
		 * @return
		 */
		@RequestMapping(value = "/sysMailAccountBatch" , produces = "text/html;charset=UTF-8")
		@ResponseBody
		public String mailAccountBatch(HttpServletRequest request,Model model)
		{
			ConstatFinalUtil.SYS_LOGGER.info("--sysMailAccountBatch--");
			Map<String, Object> condMap = new HashMap<String, Object>();
			ApiResponse<Object> apiResponse = new ApiResponse<Object>();
			/* 从session中获取信息 */
			String[] ids = request.getParameterValues("ids");
			
			/* 操作类型 */
			String operType = request.getParameter("operType");
			if(ids != null)
			{
				int totalNum = ids.length ; 
				int succedNum = 0 ; 
				int failedNum = 0 ; 
				for (int i = 0; i < ids.length; i++)
				{
					String id = ids[i];
					if("status".equalsIgnoreCase(operType))
					{
						String status = request.getParameter("status");
						
						condMap.clear();
						condMap.put("id", id);
						ApiResponse<ASysMailAccount> apiResponseDb = this.systemDbService.findOneMailAccountService(condMap);
						ASysMailAccount account = apiResponseDb.getDataOneJava();
						/* 设置状态 */
						account.setStatus(Byte.valueOf(status));
						account.setPubTime(new Date());
						
						ApiResponse<Object> accountClassResponse = this.systemDbService.updateOneMailAccountService(account);
						if(accountClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
						{
							succedNum ++ ; 
						}else
						{
							failedNum ++ ; 
						}
					}
				}
				
				StringBuffer sb = new StringBuffer();
				sb.append("总条数:" + totalNum + ";");
				sb.append("成功条数:" + succedNum + ";");
				sb.append("失败条数:" + failedNum + ";");
				apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
				apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
			}
			return apiResponse.toJSON().toJSONString();
		}
		
		/**
		 * 打开发送邮件页面页面
		 * @return
		 */
		@RequestMapping("/sysMailAccountSend")
		public String sysMailAccountSend(HttpServletRequest request,Model model)
		{
			ConstatFinalUtil.SYS_LOGGER.info("--sysMailAccountSend--");
			/* 接收测试邮箱账号的Id */
			String id = request.getParameter("id");
			if(id == null)
			{
				id = "";
			}
			if(!"".equalsIgnoreCase(id))
			{
				/* 准备查询条件 */
				Map<String, Object> condMap = new HashMap<String, Object>();
				condMap.put("id", id);
				/* 查询数据库 */
				ApiResponse<ASysMailAccount> response = this.systemDbService.findOneMailAccountService(condMap);
				/* 存储request */
				model.addAttribute("response", response.toJSON());
			}
			return "/back/system/sysMailAccountSend";
		}
		
		/**
		 * 随机选择账号发送邮件操作
		 * @return
		 */
		@RequestMapping(value = "/sysMailAccountSubmit", produces = "text/html;charset=UTF-8")
		@ResponseBody
		public String sysMailAccountSubmit(HttpServletRequest request, Model model) {
			ConstatFinalUtil.SYS_LOGGER.info("--sysMailAccountSubmit--");
			/* 接收测试邮箱账号的Id */
			String id = request.getParameter("id");
			/* 准备查询条件 */
			Map<String, Object> condMap = new HashMap<String, Object>();
			condMap.put("id", id);
			/* 查询数据库 */
			ApiResponse<ASysMailAccount> response = this.systemDbService.findOneMailAccountService(condMap);
			/* 存储request */
			ASysMailAccount sysMailAccount = response.getDataOneJava() ; 
			
			String userName = request.getParameter("userName");
			String subject = request.getParameter("subject");
			String info=request.getParameter("info");
			ApiResponse<Object> apiResponse = this.systemOperService.operSendEmail(sysMailAccount,userName, info, subject);
			return apiResponse.toJSON().toJSONString();
		}
		 
	 
		//------------------客户端列表----------------------
	
	/**
     * 客户端列表页面
     *
     * @return
     */

    @RequestMapping("/sysClientList")
    public String clientList(HttpServletRequest request, Model model) {
        ConstatFinalUtil.SYS_LOGGER.info("--clientList--");
        systemOperService.operJudgeClinetStatusList();
        /* 分页信息 */
        PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
        /* 搜索条件,生成公共的搜索条件 */
        Map<String, Object> condMap = this.proccedSearch(request);
        condMap.put("sourceType", request.getParameter("sourceType"));
		request.setAttribute("sourceType", request.getParameter("sourceType"));
        /*
         * 查询数据库 所有的数据以JSON的形式返回
         */
        ApiResponse<ASysClient> response = this.systemDbService.findCondListClientService(pageInfoUtil, condMap);
        /* 将结果存储到Request中 */
        model.addAttribute("response", response.toJSON());
        return "/back/system/sysClientList";
    }

    /**
     * 打开添加客户端页面
     *
     * @return
     */
    @RequestMapping("/sysClientInsert")
    public String clientInsert(HttpServletRequest request, Model model) {
        ConstatFinalUtil.SYS_LOGGER.info("--clientInsert--");
        return "/back/system/sysClientInsert";
    }

    /**
     * 添加客户端提交操作
     *
     * @return
     */
    @RequestMapping(value = "/clientInsertSubmit", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String clientInsertSubmit(String pubTimeStr, ASysClient client) {
        ConstatFinalUtil.SYS_LOGGER.info("--clientInsertSubmit--");
        /* 为对象赋值 */
        client.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
        client.setCreateTime(new Date());
        client.setUpdateTime(new Date());
        /* 保存结果 */
        ApiResponse response = this.systemDbService.saveOneClientService(client);
        ConstatFinalUtil.SYS_LOGGER.info("--客户端添加返回结果:{}--", response.toJSON());
        return response.toJSON().toJSONString();
    }

    /**
     * 打开更新客户端页面
     *
     * @return
     */
    @RequestMapping("/sysClientUpdate")
    public String clientUpdate(String id, String operType, Model model) {
        ConstatFinalUtil.SYS_LOGGER.info("--clientUpdate--");
        /* 准备查询条件 */
        Map<String, Object> condMap = new HashMap<String, Object>();
        condMap.put("id", id);
        /* 查询数据库 */
        ApiResponse<ASysClient> response = this.systemDbService.findOneClientService(condMap);
        /* 存储request */
        model.addAttribute("response", response.toJSON());

        if ("update".equalsIgnoreCase(operType)) {
            /* 查询所有完成的用户 */
            
            return "/back/system/sysClientUpdate";
        }
        return "/back/system/sysClientInfo";
    }

    /**
     * 添加客户端提交操作
     *
     * @return
     */
    @RequestMapping(value = "/clientUpdateSubmit", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String clientUpdateSubmit(String id,
                                      HttpServletRequest request, Model model) {
        ConstatFinalUtil.SYS_LOGGER.info("--clientUpdateSubmit--");
        /* 准备查询条件 */
        Map<String, Object> condMap = new HashMap<String, Object>();
        condMap.put("id", id);
        /* 查询数据库 */
        ApiResponse<ASysClient> response = this.systemDbService.findOneClientService(condMap);
        /* 获取java对象 */
        ASysClient client = response.getDataOneJava();

        /* 接收参数 */
        String adminsId = request.getParameter("adminsId");
        String countryId = request.getParameter("countryId");
        String ipId = request.getParameter("ipId");
        String port = request.getParameter("port");
        String sourceType = request.getParameter("sourceType");
//        String totalNum = request.getParameter("totalNum");
        String succedNum = request.getParameter("succedNum");
        String failedNum = request.getParameter("failedNum");
//        String todayTotalNum = request.getParameter("todayTotalNum");
        String todaySuccedNum = request.getParameter("todaySuccedNum");
        String todayFailedNum = request.getParameter("todayFailedNum");
        String content = request.getParameter("content");
        String status = request.getParameter("status");
        String pubTimeStr = request.getParameter("pubTimeStr");
        /* 设置属性 */
        client.setAdminsId(Integer.valueOf(adminsId));
        client.setCountryId(Integer.valueOf(countryId));
        client.setIpId(Integer.valueOf(ipId));
        client.setPort(port);
        client.setSourceType(Byte.valueOf(sourceType));
//        client.setTotalNum(Integer.valueOf(totalNum));
        client.setSuccedNum(Integer.valueOf(succedNum));
        client.setFailedNum(Integer.valueOf(failedNum)); 
//        client.setTodayTotalNum(Integer.valueOf(todayTotalNum));
        client.setTodaySuccedNum(Integer.valueOf(todaySuccedNum));
        client.setTodayFailedNum(Integer.valueOf(todayFailedNum));
        client.setContent(content);
        client.setStatus(Byte.valueOf(status));
        client.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
        client.setUpdateTime(new Date());
        /* 数据库操作 */
        ApiResponse dbRes = systemDbService.updateOneClientService(client);
        ConstatFinalUtil.SYS_LOGGER.info("--客户端添加返回结果:{}--", dbRes.toJSON());
        return dbRes.toJSON().toJSONString();
    }

    /**
     * 客户端批量操作
     *
     * @return
     */
    @RequestMapping(value = "/clientBatch", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String clientBatch(HttpServletRequest request, Model model) {
        ConstatFinalUtil.SYS_LOGGER.info("--clientBatch--");
        Map<String, Object> condMap = new HashMap<String, Object>();
        ApiResponse<Object> apiResponse = new ApiResponse<Object>();
        /* 从session中获取信息 */
        String[] ids = request.getParameterValues("ids");

        /* 操作类型 */
        String operType = request.getParameter("operType");
        if (ids != null) {
            int totalNum = ids.length;
            int succedNum = 0;
            int failedNum = 0;
            for (int i = 0; i < ids.length; i++) {
                String id = ids[i];
                if ("status".equalsIgnoreCase(operType)) {
                    String status = request.getParameter("status");

                    condMap.clear();
                    condMap.put("id", id);
                    ApiResponse<ASysClient> apiResponseDb = this.systemDbService.findOneClientService(condMap);
                    ASysClient client = apiResponseDb.getDataOneJava();
                    /* 设置状态 */
                    client.setStatus(Byte.valueOf(status));
                    client.setPubTime(new Date());

                    ApiResponse<Object> clientClassResponse = this.systemDbService.updateOneClientService(client);
                    if (clientClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus()) {
                        succedNum++;
                    } else {
                        failedNum++;
                    }
                }
            }

            StringBuffer sb = new StringBuffer();
            sb.append("总条数:" + totalNum + ";");
            sb.append("成功条数:" + succedNum + ";");
            sb.append("失败条数:" + failedNum + ";");
            apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
            apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
        }
        return apiResponse.toJSON().toJSONString();
    }
	
	//------------------客户端列表结束----------------------
    
    //------------------网站列表开始----------------------
	
  	/**
       * 网站列表页面
       *
       * @return
       */

      @RequestMapping("/sysWebSiteList")
      public String webSiteList(HttpServletRequest request, Model model) {
          ConstatFinalUtil.SYS_LOGGER.info("--webSiteList--");
          /* 分页信息 */
          PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
          /* 搜索条件,生成公共的搜索条件 */
          Map<String, Object> condMap = this.proccedSearch(request);
          String id =request.getParameter("id");
		  request.setAttribute("id",id);
		  condMap.put("id",id);
		  /*
           * 查询数据库 所有的数据以JSON的形式返回
           */
          ApiResponse<ASysWebSite> response = this.systemDbService.findCondListWebSiteService(pageInfoUtil, condMap);
          /* 将结果存储到Request中 */
          model.addAttribute("response", response.toJSON());
          return "/back/system/sysWebSiteList";
      }

      /**
       * 打开添加网站列表页面
       *
       * @return
       */
      @RequestMapping("/sysWebSiteInsert")
      public String webSiteInsert(HttpServletRequest request, Model model) {
          ConstatFinalUtil.SYS_LOGGER.info("--webSiteInsert--");
          return "/back/system/sysWebSiteInsert";
      }

      /**
       * 添加网站列表提交操作
       *
       * @return
       */
      @RequestMapping(value = "/webSiteInsertSubmit", produces = "text/html;charset=UTF-8")
      @ResponseBody
      public String webSiteInsertSubmit(String pubTimeStr, ASysWebSite website) {
          ConstatFinalUtil.SYS_LOGGER.info("--webSiteInsertSubmit--");
          /* 为对象赋值 */
          website.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
          website.setCreateTime(new Date());
          website.setUpdateTime(new Date());
          /* 保存结果 */
          ApiResponse response = this.systemDbService.saveOneWebSiteService(website);
          ConstatFinalUtil.SYS_LOGGER.info("--客户端添加返回结果:{}--", response.toJSON());
          return response.toJSON().toJSONString();
      }

      /**
       * 打开更新网站列表页面
       *
       * @return
       */
      @RequestMapping("/sysWebSiteUpdate")
      public String webSiteUpdate(String id, String operType, Model model) {
          ConstatFinalUtil.SYS_LOGGER.info("--webSiteUpdate--");
          /* 准备查询条件 */
          Map<String, Object> condMap = new HashMap<String, Object>();
          condMap.put("id", id);
          /* 查询数据库 */
          ApiResponse<ASysWebSite> response = this.systemDbService.findOneWebSiteService(condMap);
          /* 存储request */
          model.addAttribute("response", response.toJSON());

          if ("update".equalsIgnoreCase(operType)) {
              /* 查询所有完成的用户 */
              
              return "/back/system/sysWebSiteUpdate";
          }
          return "/back/system/sysWebSiteInfo";
      }

      /**
       * 添加网站列表提交操作
       *
       * @return
       */
      @RequestMapping(value = "/webSiteUpdateSubmit", produces = "text/html;charset=UTF-8")
      @ResponseBody
      public String webSiteUpdateSubmit(String id,
                                        HttpServletRequest request, Model model) {
          ConstatFinalUtil.SYS_LOGGER.info("--webSiteUpdateSubmit--");
          /* 准备查询条件 */
          Map<String, Object> condMap = new HashMap<String, Object>();
          condMap.put("id", id);
          /* 查询数据库 */
          ApiResponse<ASysWebSite> response = this.systemDbService.findOneWebSiteService(condMap);
          /* 获取java对象 */
          ASysWebSite webSite = response.getDataOneJava();

          /* 接收参数 */
          String name = request.getParameter("name");
          String url = request.getParameter("url");
          String content = request.getParameter("content");
          String status = request.getParameter("status");
          String pubTimeStr = request.getParameter("pubTimeStr");
          /* 设置属性 */
          webSite.setName(name);
          webSite.setUrl(url);
          webSite.setContent(content);
          webSite.setStatus(Byte.valueOf(status));
          webSite.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
          webSite.setUpdateTime(new Date());
          /* 数据库操作 */
          ApiResponse dbRes = systemDbService.updateOneWebSiteService(webSite);
          ConstatFinalUtil.SYS_LOGGER.info("--客户端添加返回结果:{}--", dbRes.toJSON());
          return dbRes.toJSON().toJSONString();
      }

      /**
       * 网站列表批量操作
       *
       * @return
       */
      @RequestMapping(value = "/webSiteBatch", produces = "text/html;charset=UTF-8")
      @ResponseBody
      public String webSiteBatch(HttpServletRequest request, Model model) {
          ConstatFinalUtil.SYS_LOGGER.info("--webSiteBatch--");
          Map<String, Object> condMap = new HashMap<String, Object>();
          ApiResponse<Object> apiResponse = new ApiResponse<Object>();
          /* 从session中获取信息 */
          String[] ids = request.getParameterValues("ids");

          /* 操作类型 */
          String operType = request.getParameter("operType");
          if (ids != null) {
              int totalNum = ids.length;
              int succedNum = 0;
              int failedNum = 0;
              for (int i = 0; i < ids.length; i++) {
                  String id = ids[i];
                  if ("status".equalsIgnoreCase(operType)) {
                      String status = request.getParameter("status");

                      condMap.clear();
                      condMap.put("id", id);
                      ApiResponse<ASysWebSite> apiResponseDb = this.systemDbService.findOneWebSiteService(condMap);
                      ASysWebSite webSite = apiResponseDb.getDataOneJava();
                      /* 设置状态 */
                      webSite.setStatus(Byte.valueOf(status));
                      webSite.setPubTime(new Date());

                      ApiResponse<Object> webSiteClassResponse = this.systemDbService.updateOneWebSiteService(webSite);
                      if (webSiteClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus()) {
                          succedNum++;
                      } else {
                          failedNum++;
                      }
                  }
              }

              StringBuffer sb = new StringBuffer();
              sb.append("总条数:" + totalNum + ";");
              sb.append("成功条数:" + succedNum + ";");
              sb.append("失败条数:" + failedNum + ";");
              apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
              apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
          }
          return apiResponse.toJSON().toJSONString();
      }
    //------------------网站列表结束----------------------


	/**
	 * 网站url列表页面
	 *
	 * @return
	 */
	@RequestMapping("/sysWebUrlList")
	public String sysWebUrlList(HttpServletRequest request, Model model) {
		ConstatFinalUtil.SYS_LOGGER.info("--sysWebUrlList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);

		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		String websiteId =request.getParameter("websiteId");
		request.setAttribute("websiteId",websiteId);
		condMap.put("websiteId",websiteId);

		/* 添加搜索条件 */
		String souType = request.getParameter("souType");
		request.setAttribute("souType", souType);
		condMap.put("souType", souType);
		
		String reqtype = request.getParameter("reqtype");
		request.setAttribute("reqtype", reqtype);
		condMap.put("reqtype", reqtype);

		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<ASysWebUrl> response = this.systemDbService.findCondListWebUrlService(pageInfoUtil, condMap);

		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());

		return "/back/system/sysWebUrlList";
	}

	/**
	 * 打开添加网站url页面
	 *
	 * @return
	 */
	@RequestMapping("/sysWebUrlInsert")
	public String taskWebUrlInsert(HttpServletRequest request, Model model) {
		ConstatFinalUtil.SYS_LOGGER.info("--WebUrlInsert--");
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/* 查询所有启用的网站id */
		condMap.clear();
		condMap.put("status", ASysWebSiteEnum.STATUS_ENABLE.getStatus());
		ApiResponse<ASysWebSite> websiteResponse = this.systemDbService.findCondListWebSiteService(null, condMap);
		model.addAttribute("websiteResponse", websiteResponse.toJSON());
		return "/back/system/sysWebUrlInsert";
	}

	/**
	 * 添加网站url提交操作
	 *
	 * @return
	 */
	@RequestMapping(value = "/sysWebUrlInsertSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String taskWebUrlInsertSubmit(String pubTimeStr, ASysWebUrl sysWebUrl, HttpServletRequest request) {
		ConstatFinalUtil.SYS_LOGGER.info("--sysWebUrlInsertSubmit--");
		/* 为对象赋值 */
		sysWebUrl.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		sysWebUrl.setCreateTime(new Date());
		sysWebUrl.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.systemDbService.saveOneWebUrlService(sysWebUrl);
		ConstatFinalUtil.SYS_LOGGER.info("--网站url添加返回结果:{}--", response.toJSON());
		return response.toJSON().toJSONString();
	}

	/**
	 * 打开更新网站url页面
	 *
	 * @return
	 */
	@RequestMapping("/sysWebUrlUpdate")
	public String taskWebUrlUpdate(String id, String operType, Model model) {
		ConstatFinalUtil.SYS_LOGGER.info("--sysWebUrlUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysWebUrl> response = this.systemDbService.findOneWebUrlService(condMap);

		/* 存储request */
		model.addAttribute("response", response.toJSON());

		if ("update".equalsIgnoreCase(operType)) {
			/* 查询所有启用的网站id */
			condMap.clear();
			condMap.put("status", ASysWebSiteEnum.STATUS_ENABLE.getStatus());
			ApiResponse<ASysWebSite> websiteResponse = this.systemDbService.findCondListWebSiteService(null, condMap);
			model.addAttribute("websiteResponse", websiteResponse.toJSON());

			return "/back/system/sysWebUrlUpdate";
		}
		return "/back/system/sysWebUrlInfo";
	}

	/**     
	 * 添加网站url提交操作
	 *
	 * @return
	 */
	@RequestMapping(value = "/sysWebUrlUpdateSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String taskWebUrlUpdateSubmit(String id,
									   HttpServletRequest request, Model model) {
		ConstatFinalUtil.SYS_LOGGER.info("--sysWebUrlUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysWebUrl> response = this.systemDbService.findOneWebUrlService(condMap);
		/* 获取java对象 */
		ASysWebUrl sysWebUrl = response.getDataOneJava();

		/* 接收参数 */
		String websiteId =request.getParameter("websiteId");
		String name = request.getParameter("name");
		String url = request.getParameter("url");
		String totalCount = request.getParameter("totalCount");
		String reqtype = request.getParameter("reqtype");
		String method =request.getParameter("method");
		String batchSize =request.getParameter("batchSize");
		String headerNum =request.getParameter("headerNum");
		String pageSize =request.getParameter("pageSize");
		String notifyUrl =request.getParameter("notifyUrl");
		String content = request.getParameter("content");
		String souType = request.getParameter("souType");
		String status = request.getParameter("status");
		String pubTimeStr = request.getParameter("pubTimeStr");
		/* 设置属性 */
		sysWebUrl.setWebsiteId(Integer.valueOf(websiteId));
		sysWebUrl.setName(name);
        sysWebUrl.setUrl(url);
        sysWebUrl.setTotalCount(Integer.valueOf(totalCount));
		sysWebUrl.setReqtype(Integer.valueOf(reqtype));
        sysWebUrl.setMethod(method);
        sysWebUrl.setBatchSize(Integer.valueOf(batchSize));
        sysWebUrl.setHeaderNum(Integer.valueOf(headerNum));
		sysWebUrl.setPageSize(Integer.valueOf(pageSize));
		sysWebUrl.setNotifyUrl(notifyUrl);
		sysWebUrl.setContent(content);
		sysWebUrl.setSouType(Byte.valueOf(souType));
		sysWebUrl.setStatus(Byte.valueOf(status));
		sysWebUrl.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		sysWebUrl.setUpdateTime(new Date());

		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneWebUrlService(sysWebUrl);
		ConstatFinalUtil.SYS_LOGGER.info("--网站url添加返回结果:{}--", dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}

	/**
	 * 网站url批量操作
	 *
	 * @return
	 */
	@RequestMapping(value = "/sysWebUrlBatch", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String taskWebUrlBatch(HttpServletRequest request, Model model) {
		ConstatFinalUtil.SYS_LOGGER.info("--sysWebUrlBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");

		/* 操作类型 */
		String operType = request.getParameter("operType");
		if (ids != null) {
			int totalNum = ids.length;
			int succedNum = 0;
			int failedNum = 0;
			for (int i = 0; i < ids.length; i++) {
				String id = ids[i];
				if ("status".equalsIgnoreCase(operType)) {
					String status = request.getParameter("status");

					condMap.clear();
					condMap.put("id", id);
					ApiResponse<ASysWebUrl> apiResponseDb = this.systemDbService.findOneWebUrlService(condMap);
					ASysWebUrl sysWebUrl = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					sysWebUrl.setStatus(Byte.valueOf(status));
					sysWebUrl.setPubTime(new Date());

					ApiResponse<Object> taskWebUrlClassResponse = this.systemDbService.updateOneWebUrlService(sysWebUrl);
					if (taskWebUrlClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus()) {
						succedNum++;
					} else {
						failedNum++;
					}
				}
			}

			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
	@RequestMapping("getQRCodeUrl")
	public void getQRCodeUrl(HttpServletRequest request, HttpServletResponse response) throws Exception{

		ConstatFinalUtil.SYS_LOGGER.info("=====getQRCodeUrl=====");
		String content = request.getParameter("WebUrl");
		response.setContentType("image/png");
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		//存入会话session  
		HttpSession session = request.getSession(true);
		session.setAttribute("randSess", content);
		BufferedImage image =null;
		if(content.startsWith("https://")) {
			image = QRcodeUtil.operGetEncode(content);
		}else {
			image = QRcodeUtil.operGetEncode("https://"+content);
		}

		ImageIO.write(image, "png", response.getOutputStream());
	}		
			 
	/**
	 * 邮箱账号列表页面
	 * 
	 * @return
	 */
	@RequestMapping("/sysShortUrlList")
	public String shortUrlList(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysMailAccountList--");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/*
		 * 查询数据库 所有的数据以JSON的形式返回
		 */
		ApiResponse<ASysShortUrl> response = this.systemDbService.findCondListShortUrlService(pageInfoUtil, condMap);
		/* 将结果存储到Request中 */
		model.addAttribute("response", response.toJSON());
		return "/back/system/sysShortUrlList";
	}

	/**
	 * 打开添加邮箱账号页面
	 * 
	 * @return
	 */
	@RequestMapping("/sysShortUrlInsert")
	public String shortUrlInsert()
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysShortUrlInsert--");
		return "/back/system/sysShortUrlInsert";
	}

	   
	/**
	 * 添加邮箱账号提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/sysShortUrlInsertSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String shortUrlInsertSubmit(HttpServletRequest request, String pubTimeStr, ASysShortUrl shortUrl)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysShortUrlInsertSubmit--");
		ApiResponse<Object> response = new ApiResponse<Object>();

		Map<String, Object> condMap = new HashMap<String, Object>();
		String url = request.getParameter("long_url");
		condMap.put("long_url", url);
		ApiResponse<ASysShortUrl> apiResponse = this.systemDbService.findOneShortUrlService(condMap);
		if (apiResponse.getDataOneJava() == null)
		{
			ASysShortUrl sysShortUrl = new  ASysShortUrl();
			/* 接收参数 */
			String long_url = request.getParameter("long_url");
			String shortUrl2 = generateShortUtil.gererateShortUrl(url);
			String status = request.getParameter("status");
			String pubTimeStr1 = request.getParameter("pubTimeStr");
			String content = request.getParameter("content");
			/* 设置属性 */
			sysShortUrl.setShort_url(shortUrl2);
			sysShortUrl.setLong_url(long_url);
			sysShortUrl.setContent(content);
			sysShortUrl.setStatus(Byte.valueOf(status));
			sysShortUrl.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr1));
			sysShortUrl.setUpdateTime(new Date());
			sysShortUrl.setCreateTime(new Date());
			response = systemDbService.saveOneShortUrlService(sysShortUrl);
			 
		} else
		{
			response.setInfo("数据已存在", Collections.EMPTY_MAP);
		}

		return response.toJSON().toJSONString();
	}

	/**
	 * 打开更新邮箱账号页面
	 * 
	 * @return
	 */
	@RequestMapping("/sysShortUrlUpdate")
	public String shortUrlUpdate(String id, String operType, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysShortUrlUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysShortUrl> response = this.systemDbService.findOneShortUrlService(condMap);
		/* 存储request */
		model.addAttribute("response", response.toJSON());

		if ("update".equalsIgnoreCase(operType))
		{
			return "/back/system/sysShortUrlUpdate";
		}
		return "/back/system/sysShortUrlInfo";
	}

	/**
	 * 添加邮箱账号提交操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/sysShortUrlUpdateSubmit", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String shortUrlUpdateSubmit(String id, HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysShortUrlUpdateSubmit--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ASysShortUrl> response = this.systemDbService.findOneShortUrlService(condMap);
		/* 获取java对象 */
		ASysShortUrl shortUrl = response.getDataOneJava();

		/* 接收参数 */
		String short_url = request.getParameter("short_url");
		String long_url = request.getParameter("long_url");
		String status = request.getParameter("status");
		String pubTimeStr = request.getParameter("pubTimeStr");
		String content = request.getParameter("content");
		/* 设置属性 */

		shortUrl.setShort_url(short_url);
		shortUrl.setLong_url(long_url);
		shortUrl.setContent(content);
		shortUrl.setStatus(Byte.valueOf(status));

		shortUrl.setPubTime(this.dateFormatUtil.strDateTime(pubTimeStr));
		shortUrl.setUpdateTime(new Date());
		/* 数据库操作 */
		ApiResponse dbRes = systemDbService.updateOneShortUrlService(shortUrl);
		ConstatFinalUtil.SYS_LOGGER.info("--sysCountry添加返回结果:{}--", dbRes.toJSON());
		return dbRes.toJSON().toJSONString();
	}

	/**
	 * 邮箱账号批量操作
	 * 
	 * @return
	 */
	@RequestMapping(value = "/sysShortUrlBatch", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String shortUrlBatch(HttpServletRequest request, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--sysShortUrlBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");

		/* 操作类型 */
		String operType = request.getParameter("operType");
		if (ids != null)
		{
			int totalNum = ids.length;
			int succedNum = 0;
			int failedNum = 0;
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if ("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");

					condMap.clear();
					condMap.put("id", id);
					ApiResponse<ASysShortUrl> apiResponseDb = this.systemDbService.findOneShortUrlService(condMap);
					ASysShortUrl shortUrl = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					shortUrl.setStatus(Byte.valueOf(status));
					shortUrl.setPubTime(new Date());

					ApiResponse<Object> shortUrlClassResponse = this.systemDbService.updateOneShortUrlService(shortUrl);
					if (shortUrlClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum++;
					} else
					{
						failedNum++;
					}
				}
			}

			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
}
